/*
题目描述
设已经存在Student类定义如下，类型只支持String和Integer
class Student{
  public String stdname;
  public Integer stdcode;
  public Student(String stdname,Integer stdcode) {
	  this.stdname=stdname;
	  this.stdcode=stdcode;
  }
  public Student(String stdname) {
	  this.stdname=stdname;
	  this.stdcode=new Random().nextInt();
  }
  public void study(String lesson) {
	  System.out.println(stdname+" learning "+lesson);
  }
  public void setName(String stdname) {
	  this.stdname=stdname;
  }
  public void doSomeHelp(Student s) {
	  System.out.println(stdname+" help "+s.stdname);
  }
}

请识别输入的命令，进行对象的创建和方法调用。
不存在的方法输出：Wrong Method
不存在的变量输出：Wrong Variable
构造函数不存在输出： Wrong Constructor
不存在的类型输出： Wrong Type
其他异常输出：Wrong Statement
限定：每行一个命令

样例输入输出
样例1
输入:
Student s=new Student("zhangsan",20);
s.setName("lisi");
s.doSomeHelp(s);
s.study();
s.study("java");
输出:
lisi help lisi
Wrong Method
lisi learning java

样例2
输入:
Student s1=new Student ("Mary",20);
s1.study("Database");
Student s2=new Student("Tom",1);
s1.doSomeHelp(s2);
s2.study("Data");
s1.doSomeHelp(s0);
s1.doSomeHelp("Tom");
s2=new Student();
输出:
Mary learning Database
Mary help Tom
Tom learning Data
Wrong Variable
Wrong Method
Wrong Constructor

样例3
输入:
Teacher t=new Teacher();
输出:
Wrong Type

 */
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
import java.util.Scanner;

class Student {
    public String stdname;
    public Integer stdcode;
    public Student(String stdname, Integer stdcode) {
        this.stdname = stdname;
        this.stdcode = stdcode;
    }
    public Student(String stdname) {
        this.stdname = stdname;
        this.stdcode = new Random().nextInt();
    }
    public void study(String lesson) {
        System.out.println(stdname + " learning " + lesson);
    }
    public void setName(String stdname) {
        this.stdname = stdname;
    }
    public void doSomeHelp(Student s) {
        System.out.println(stdname + " help " + s.stdname);
    }
}

public class Main {
    static Object createNew(String classname, Object[] para, Class[] paratype)
            throws ClassNotFoundException, NoSuchMethodException, SecurityException,
            InstantiationException, IllegalAccessException, IllegalArgumentException,
            InvocationTargetException {
        Class<?> c = Class.forName(classname);
        Constructor<?> cons = c.getConstructor(paratype);
        return cons.newInstance(para);
    }

    static Object methodCall(Object obj, String methodName, Class[] paratype, Object[] para)
            throws NoSuchMethodException, SecurityException, IllegalAccessException,
            IllegalArgumentException, InvocationTargetException {
        Class<?> type = obj.getClass();
        Method method = type.getMethod(methodName, paratype);
        return method.invoke(obj, para);
    }

    static void getPara(String state, ArrayList<Object> para, ArrayList<Class<?>> paratype,
                        HashMap<String, Object> valist) throws Exception {
        if (state.trim().length() == 0) {
            return;
        }

        String[] param = state.split(",");

        for (String par : param) {
            par = par.trim();
            if (par.contains("\"")) {
                paratype.add(String.class);
                para.add(par.replace("\"", ""));
            } else {
                try {
                    para.add(Integer.parseInt(par));
                    paratype.add(Integer.class);
                } catch (NumberFormatException e) {
                    Object o = valist.get(par);
                    if (o != null) {
                        paratype.add(o.getClass());
                        para.add(o);
                    } else {
                        throw new Exception("Wrong Variable");
                    }
                }
            }
        }
    }

    static Object invo(String state, HashMap<String, Object> valist) throws Exception {
        int pos = state.indexOf(".");
        if (pos == -1) {
            throw new Exception("Wrong Statement");
        }

        String objname = state.substring(0, pos).trim();
        Object value = valist.get(objname);
        if (value == null) {
            throw new Exception("Wrong Variable");
        }

        String methodname = state.substring(pos + 1).trim();
        pos = methodname.indexOf("(");
        int pos2 = methodname.indexOf(")");

        if (pos == -1 || pos2 == -1) {
            throw new Exception("Wrong Statement");
        }

        String method = methodname.substring(0, pos);
        String parastr = methodname.substring(pos + 1, pos2);

        ArrayList<Object> ol = new ArrayList<>();
        ArrayList<Class<?>> tl = new ArrayList<>();

        getPara(parastr, ol, tl, valist);
        Object[] para = ol.toArray();
        Class<?>[] paratype = tl.toArray(new Class<?>[0]);

        try {
            return methodCall(value, method, paratype, para);
        } catch (NoSuchMethodException e) {
            throw new Exception("Wrong Method");
        } catch (IllegalArgumentException e) {
            throw new Exception("Wrong Method");
        } catch (InvocationTargetException e) {
            throw new Exception("Wrong Statement");
        }
    }

    public static void main(String[] arg) {
        HashMap<String, Object> va = new HashMap<>();
        Scanner scan = new Scanner(System.in);

        while (scan.hasNext()) {
            String stat = scan.nextLine().trim();
            try {
                if (stat.contains("=")) {
                    String[] stats = stat.split("=", 2);
                    String target = stats[0].trim();
                    String source = stats[1].trim();
                    String typestr = "";
                    String valuename = "";

                    if (target.contains(" ")) {
                        String[] parts = target.split("\\s+", 2);
                        typestr = parts[0].trim();
                        valuename = parts[1].trim();

                        if (!typestr.equals("Student")) {
                            throw new Exception("Wrong Type");
                        }
                    } else {
                        valuename = target;
                    }

                    if (source.startsWith("new ")) {
                        int pos = source.indexOf("(", 4);
                        if (pos == -1) {
                            throw new Exception("Wrong Constructor");
                        }

                        String sourtypestr = source.substring(4, pos).trim();
                        if (!sourtypestr.equals("Student")) {
                            throw new Exception("Wrong Type");
                        }

                        int pos2 = source.indexOf(")", pos);
                        if (pos2 == -1) {
                            throw new Exception("Wrong Constructor");
                        }

                        ArrayList<Object> ol = new ArrayList<>();
                        ArrayList<Class<?>> tl = new ArrayList<>();

                        getPara(source.substring(pos + 1, pos2), ol, tl, va);
                        Object[] para = ol.toArray();
                        Class<?>[] paratype = tl.toArray(new Class<?>[0]);

                        try {
                            Object obj = createNew(sourtypestr, para, paratype);
                            va.put(valuename, obj);
                        } catch (NoSuchMethodException e) {
                            throw new Exception("Wrong Constructor");
                        } catch (ClassNotFoundException e) {
                            throw new Exception("Wrong Type");
                        }
                    } else if (source.contains(".")) {
                        Object obj = invo(source, va);
                        va.put(valuename, obj);
                    } else {
                        Object obj = va.get(source);
                        if (obj != null) {
                            va.put(valuename, obj);
                        } else {
                            throw new Exception("Wrong Variable");
                        }
                    }
                } else {
                    invo(stat, va);
                }
            } catch (Exception e) {
                String msg = e.getMessage();
                if (msg == null || msg.isEmpty()) {
                    System.out.println("Wrong Statement");
                } else {
                    System.out.println(msg);
                }
            }
        }
        scan.close();
    }
}
